#pragma once
#include <string>
#include <vector>
#include <string>
#include <list>
#include <string>
#include <type_traits>
class StringTool
{
public:
    // 获取字符串
    static std::string getString(const char *str, bool bIsDeepCopy);
    // 去除首位空白字符
    static std::string trim(const std::string &str);
    // 分割字符串
    static std::vector<std::string> split(const std::string &str, char delim);
    static std::vector<std::string> split(const std::string &str, const std::string &delim);
    // 合并字符串
    template <class VECTOR_TYPE>
    static std::string join(const VECTOR_TYPE &strs, const std::string &delim)
    {
        if (strs.size() > 0)
        {
            std::string str;
            for (auto it = strs.begin(); it != strs.end(); it++)
            {
                str += *it;
            }
            str = str.substr(0, str.find_last_of(delim) + 1);
            return str;
        }
    }
	static size_t right(const std::string &str, const std::string &delim)
	{
		return str.find_last_of(delim);
	}
	// 辅助函数：将不同类型转换为std::string
	template<typename T>
	std::string to_string(const T& value) {
		if (std::is_arithmetic<T>::value) {
			return std::to_string(value);
		} else {
			return std::string(value);
		}
	}

	// 辅助函数：检查类型是否可以转换为std::string
	template<typename T>
	struct is_convertible_to_string {
		static constexpr bool value = std::is_convertible<T, std::string>::value || std::is_arithmetic<T>::value;
	};

	// // 递归模板函数：处理占位符替换
	// template <typename... Args>
	// struct ArgReplacer;

	// template <>
	// struct ArgReplacer<> {
	// 	static std::string replace(const std::string& fmt) {
	// 		return fmt;
	// 	}
	// };

	// template <typename First, typename... Rest>
	// struct ArgReplacer<First, Rest...> {
	// 	static std::string replace(const std::string& fmt, First&& first, Rest&&... rest) {
	// 		std::string result = fmt;
	// 		size_t argIndex = sizeof...(Rest); // Calculate the current argument index
	// 		std::string placeholder = "%" + std::to_string(sizeof...(Rest) + 1) + "%";
	// 		size_t pos = 0;
	// 		while ((pos = result.find(placeholder, pos)) != std::string::npos) {
	// 			result.replace(pos, placeholder.length(), to_string(std::forward<First>(first)));
	// 			pos += to_string(std::forward<First>(first)).length();
	// 		}
	// 		return ArgReplacer<Rest...>::replace(result, std::forward<Rest>(rest)...);
	// 	}
	// };

	// // 主模板函数：使用SFINAE确保参数类型正确
	// template <typename... Args>
	// typename std::enable_if<(sizeof...(Args) >= 1 && ... && is_convertible_to_string<Args>::value), std::string>::type
	// arg(const std::string& fmt, Args&&... args) {
	// 	return ArgReplacer<Args...>::replace(fmt, std::forward<Args>(args)...);
	// }

// 测试用例
/* int main() {
    std::string text = "Hello %1%, your score is %2%. You are in %3%. Pi is approximately %4%.";
    auto result = arg(text, std::string("Alice"), 95, std::string("New York"), 3.14159);

    std::cout << result << std::endl; // 输出: Hello Alice, your score is 95. You are in New York. Pi is approximately 3.14159.
} */
};

namespace xcom
{
class string{
    string() = default;
    ~string() = default;
    
private:
    std::string m_str;
};
} // namespace xcom
